package com.wkh.maker.cli.command;

import cn.hutool.core.bean.BeanUtil;
import com.wkh.maker.generator.file.FileGenerator;
import com.wkh.maker.model.DataModel;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
 * @author wkh
 * 代码生成器的核心命令，作用是接收参数生成代码
 */
@Data
@CommandLine.Command(name = "generator",description = "生成代码",mixinStandardHelpOptions = true)
public class GeneratorCommand implements Callable {

    @CommandLine.Option(names = {"-a","--author"},arity = "0..1",interactive = true,description = "作者",echo = true)
    //作者
    private String author = "wkh";
    @CommandLine.Option(names = {"-o","--outputText"},arity = "0..1",interactive = true,description = "输出文本",echo = true)
    //输出信息
    private String outputText = "sum = ";
    @CommandLine.Option(names = {"-l","--loop"},arity = "0..1",interactive = true,description = "是否循环",echo = true)
    //是否开启循环(开关)
    private boolean loop;

    @Override
    public Object call() throws Exception {
        DataModel mainTemplateConfig = new DataModel();
        //属性拷贝
        BeanUtil.copyProperties(this,mainTemplateConfig);
        System.out.println("配置信息:"+mainTemplateConfig);
        //生成代码
        FileGenerator.doGenerator(mainTemplateConfig);
        return 0;
    }
}
